## Assumes that the current working directory is the top dir of the archive
## Run in R 3.0.3 -- "Frisbee Sailing"

library(foreign)

home <- getwd()
## This is the script that does the mahalanobis matching
source(paste(home,"/aid/scripts/runBigMahal_Aid.R",sep=""))

agr <- c("iccpr","opt1","cat","art22")


for(i in 1:4){
  HRA <- agr[i]
  print(HRA)

  ## All observation matching
  if(!file.exists(paste(home,"/aid/madedata/mahmatches_",HRA,"aid.dta",sep=""))){
    runBigMahal_Aid(HRA=HRA, 
      inData=paste(home,"/aid/madedata/",HRA,"RatEpisodeDat.dta",sep=""),
      outData=paste(home,"/aid/madedata/mahmatches_",HRA,"aid.dta",sep=""))
  }

  ## if HRAname_1==1 & HRAname_2==0 (looking at decisions by ratifiers to sign with other countries   that have not yet ratified)
  if(!file.exists(paste(home,"/aid/madedata/mahmatches_",HRA,"aid_Ratifiers.dta",sep=""))){
    runBigMahal_Aid(HRA=HRA, 
      inData=paste(home,"/aid/madedata/",HRA,"RatEpisodeDat_Ratifiers.dta",sep=""),
      outData=paste(home,"/aid/madedata/mahmatches_",HRA,"aid_Ratifiers.dta",sep=""))
  }

  ## if HRAname_2==0 (looking at decisions by ratifiers to sign with other countries that have not   yet ratified)
  if(!file.exists(paste(home,"/aid/madedata/mahmatches_",HRA,"aid_nonRatifiers.dta",sep=""))){
    runBigMahal_Aid(HRA=HRA, 
      inData=paste(home,"/aid/madedata/",HRA,"RatEpisodeDat_nonRatifiers.dta",sep=""),
      outData=paste(home,"/aid/madedata/mahmatches_",HRA,"aid_nonRatifiers.dta",sep=""))
  }
}

